﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using BUS;

namespace GUI
{
    public partial class frmDangNhap : DevComponents.DotNetBar.Office2007Form
    {
        public frmDangNhap()
        {
            InitializeComponent();
        }

        public bool isDangNhapThanhCong = false;

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (txtMaNV.Text == "")
            {
                MessageBox.Show("Nhập mã nhân viên");
                txtMaNV.Focus();
            }
            else
                if (txtMatKhau.Text == "")
                {
                    MessageBox.Show("Nhập mật khẩu");
                    txtMatKhau.Focus();
                }
                else
                {
                    //tiến hành kiểm tra để đăng nhập
                    int maNV = int.Parse(txtMaNV.Text);
                    string matKhau = md5.maHoaMd5(txtMatKhau.Text);

                    if (NhanVienBUS.dangNhap(maNV, matKhau))
                    {
                        isDangNhapThanhCong = true;
                        //nhanvien = NhanVienBUS.layNV(maNV);
                        this.Hide();
                        frmMain frmChinh = new frmMain();
                        frmChinh.nhanvien = NhanVienBUS.layNV(maNV);
                        frmChinh.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("Sai mật khẩu hay mã nhân viên. Vui lòng điền thông tin chính xác.");
                        txtMaNV.Text = "";
                        txtMatKhau.Text = "";
                        txtMaNV.Focus();
                    }
                }
        }

        private void frmDangNhap_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
